
/* ----------------
* Arquivo: nfi.h
* ----------------
*/

#ifndef INTNF_H
#define INTNF_H

//////////////////////////////////////////////////////////////////////
// 		structure to store node information
//////////////////////////////////////////////////////////////////////
typedef struct _Tnode_data {

 int           id;       // element id
 double        x;
 double        y;
 double        z;
}Tnode_data;


//////////////////////////////////////////////////////////////////////
// 	Structure to store nodal support
//////////////////////////////////////////////////////////////////////
typedef struct _sup_data
{
   int         id;
   int         dx, dy, dz, rx, ry, rz;
} Tsup_data;


//////////////////////////////////////////////////////////////////////
// 	Structure to store 3D elements
//////////////////////////////////////////////////////////////////////
typedef struct _element_3d
{
  int          type;                // element type

  int          id;                  // element id
  int          n;                   // number of nodes
  int          inc[20];             // incidence nodes
  int          mat;                 // material id
}Telement_3d;

/** Tipos de Elemento */
typedef enum _shapetype{ 
/** '-1' undef                */ NF_UNDEF = -1,
/** '0' 4-noded tetrahedron   */ NF_TETR4 = 0,
/** '1' 10-noded tetrahedron  */ NF_TETR10,
/** '2' 8-noded brick         */ NF_BRICK8,
/** '3' 20-noded brick        */ NF_BRICK20,
/** '4' 6-noded wedge         */ NF_WEDGE6,
/** '5' 15-noded wedge        */ NF_WEDGE15,
/** total number of elements  */ NumShapeTypes, 
}ShapeType;


//////////////////////////////////////////////////////////////////////
// 	Structure to store material isotropic
//////////////////////////////////////////////////////////////////////
typedef struct _mat_isotropic
{
  int          id;
  char         label[20];
  
  double       e;
  double       nu;

  double       **C;    // contitutive matrix
  double       **invC; // inverse of contitutive matrix
} Tmat_isotropic;


/* NODAL.FORCE */
typedef struct nf_nodal_force
{
  int   id;
  float Fx , Fy , Fz, Mx, My, Mz;
} TNodalForce;

/* AREA.PRESSURE.UNIFORM */
typedef struct nf_pressure_uniform
{
  int   id, id_i, id_j, id_k, key;
  float px, py, pz;
} TAreaPressureUniform;

/* AREA.PRESSURE.VARIABLE */
typedef struct nf_pressure_variable
{
  int   id, id_i, id_j, id_k, key;
  float px1, py1, pz1;
  float px2, py2, pz2;
} TAreaPressureVariable;

/*  */
typedef struct nf_field
{
  char label[20];
} nfField;

/* element information */
typedef struct nf_elem_info
{
  int      npts;
  double **values;  /* npts x nfields */
} nfElemInfo;


typedef struct nf_elem_result
{
  int      nfields;
  nfField *fields;

  int  sxx, sxy, sxz, syx, syy, syz, szx, szy, szz;  // fields position

  nfElemInfo *elemInfo;
} ElemResult;


typedef struct nf_result
{
  ElemResult  *ElementNodal;
  ElemResult  *ElementGauss;
} nfResullt;

typedef struct nf_tensor
{
 double sxx;
 double sxy;
 double sxz;
 double syx;
 double syy;
 double syz;
 double szx;
 double szy;
 double szz;
 double mxx;
 double mxy;
 double mxz;
 double myx;
 double myy;
 double myz;
 double mzx;
 double mzy;
 double mzz;
} nfStressTensor;

//////////////////////////////////////////////////////////////////////
// 	Structure to store mesh and attibutes
//////////////////////////////////////////////////////////////////////
class TMesh3D
{

public:
  // Mesh
  int            nnodes;     // # nodes 
  Tnode_data     *nodes;     // coord. nodes
  int            nelems;     // # elements
  Telement_3d    *elems;      // elements
  
  int            nsupport;   // # support
  Tsup_data      *support;   // support

  int            nmaterial;  // # material
  Tmat_isotropic *mat;       // materials

  int            nfnodal;
  TNodalForce    *fnodal;

  int                  nupressure;
  TAreaPressureUniform *upressure;

  int                    nvpressure;
  TAreaPressureVariable* vpressure;

  nfResullt    *results;

  // construtor
  TMesh3D ( )
  {
    nnodes = 0;
    nelems = 0;
    nodes = NULL;
    elems = NULL;

    nsupport = 0;
    support = NULL;

    nmaterial = 0;
    mat = NULL;

    nfnodal = 0;
    fnodal = NULL;

    nupressure = 0;
    upressure = NULL;

    nvpressure = 0;
    vpressure = NULL;

    results = NULL;
  };

  // destrutor
  ~TMesh3D ( )
  {
    if (nodes == NULL)
      delete []nodes;

    if (elems == NULL)
      delete []elems;

    if (support == NULL)
      delete []support;

    if (mat == NULL)
      delete []mat;

    if (fnodal == NULL)
      delete []fnodal;

    if (upressure == NULL)
      delete []upressure;

    if (vpressure == NULL)
      delete []vpressure;

  };


};




//////////////////////////////////////////////////////////////////////
// 	Global Functions
//////////////////////////////////////////////////////////////////////

int  NfiInterp (FILE *file, TMesh3D *mesh);

#endif
